package ElectricCraft.drawer;

/**
 *  Base drawer interface that provides ElectricCraft primitives rendering.
 */
public abstract class Drawer {
	protected static final int itemSize = 20;
	public int getItemSize() {
		return itemSize;
	}

	protected int drawPosX = 0;
	protected int drawPosY = 0;
	public void setDrawPos(int x, int y) {
		this.drawPosX = x;
		this.drawPosY = y;
	}

    // TODO: wire info should be property of model
	public static final int WIRE_SINGLE = 0x0010;
	public static final int WIRE_FULL   = 0x001f;
	public static final int WIRE_CROSS  = 0x003f;
	public static int getWireTypeByDirs(boolean [] dirs) {
		int res = WIRE_SINGLE;
		for (int k = 0; k < dirs.length; ++k) {
			if (dirs[k]) {
				res |= 1 << k;
			}
		}
		return res;
	}

    public static final int CHIP_OUTPUT_BIT = 0x0100;
    public static final int CHIP_INDEX_MASK = 0x00ff;
    public static final int CHIP_COUNT_OFFSET = 9;
    public static int getChipOrientation(int index, boolean isInput, int count) {
        int res = index;
        if (!isInput) {
            res |= CHIP_OUTPUT_BIT;
        }
        res |= count << CHIP_COUNT_OFFSET;
        return res;
    }

    public static boolean isInputChipPart(int orientation) {
        return (orientation & CHIP_OUTPUT_BIT) == 0;
    }

	public abstract void setClipRect    (int x, int y, int width, int height);

	public abstract void drawWire       (int type, int activeMask);
	public abstract void drawDiode      (int orientation);
	public abstract void drawKey        (int orientation, boolean state); // true means 'connected'
	public abstract void drawPower      ();
	public abstract void drawInput      (int index);
	public abstract void drawOutput     (int index);

    public abstract void drawPreviewChip();
    public abstract void drawChipPart   (int orientation);

	public abstract void drawGrid       (int countX, int countY);
	public abstract void drawEditGrid   (int countX, int countY);

	public abstract void pushTransform  (double dx, double dy);
	public abstract void pushTransform  (double dx, double dy, double scale);
	public abstract void pushTransform  (double dx, double dy, double scale, double rotate);

	public abstract void popTransform();
}
